const md5 = require('md5');
const jsonwebtoken = require('jsonwebtoken');
const { key } = require('./types');
// 转小写
exports.lowerCase = (str) => str.toLowerCase()

// 加密
exports.encryption = (props) => ({ ...props, password: md5(props.password) })

// 构造token
exports.createToken = (props) => {
    return jsonwebtoken.sign(props, key);
}

//校验token
exports.validateToken = (token) => {
    token = token.split(' ')[1];
    return jsonwebtoken.verify(token, key);
}

